package com.catalog.Manager
{
	import com.catalog.ValueObject.MainPageVO;
	import com.catalog.ValueObject.PicturePageVO;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.mxml.HTTPService;
	
	[Event(name="LoadModuleConfigComplete",type="flash.events.Event")]
	
	public class ConfigManager extends EventDispatcher
	{
		public static const MAIN_PAGE_CONFIG_URL:String = "Resource/config/MainPageConfig.xml";
		
		[Bindable]
		public var ModuleList:ArrayCollection = new ArrayCollection();
		

		
		public function ConfigManager()
		{
			super();
			getMainPageConfig();
			
		}
		
		private static var _instance:ConfigManager;
		public static function getInstance():ConfigManager
		{
			if( !_instance )
				_instance = new ConfigManager();
			return _instance;
		}
		
		/**
		 *  获取主配置文件 
		 * 
		 */		
		private function getMainPageConfig():void
		{
			var httpService:HTTPService = new HTTPService();
			httpService.addEventListener(ResultEvent.RESULT,onMainPageConfigResultHandler );
			httpService.resultFormat = "e4x";
			httpService.url = MAIN_PAGE_CONFIG_URL;
			httpService.send();
		}
		
		private function onMainPageConfigResultHandler( event:ResultEvent ):void
		{
			var resultXml:XML = event.result as XML;
			for each( var item:XML in resultXml.Page )
			{
				var page:MainPageVO = new MainPageVO();
				page.label = item.@label;
				page.url = item.@url;
				page.iconSource = item.@iconSource;
				ModuleList.addItem( page );
			}
			ModuleList.refresh();
			dispatchEvent(new Event("LoadModuleConfigComplete"));
		}
	}
}